﻿
import defSet from '@/settings'
/**
 * 商城模块通用js方法封装处理
 * Copyright (c) 2019 ruoyi
 */
export default {
  // 跳转买家端商品
  linkTo(goodsId, skuId) {
    window.open(`${defSet.mallConf.PC_URL}/goodsDetail?skuId=${skuId}&goodsId=${goodsId}`, '_blank')
  },

// app端二维码
  wapLinkTo(goodsId, skuId) {
    return `${defSet.mallConf.WAP_URL}/pages/product/goods?id=${skuId}&goodsId=${goodsId}`
  },

  /**
   * 金钱单位置换  2999 --> 2,999.00
   * @param val
   * @param unit
   * @param location
   * @returns {*}
   */
  unitPrice(val, unit, location) {
    let price = this.formatPrice(val)
    if (location === 'before') {
      return price.substr(0, price.length - 3)
    }
    if (location === 'after') {
      return price.substr(-2)
    }
    return (unit || '') + price
  },

  /**
   * 货币格式化
   * @param price
   * @returns {string}
   */
  formatPrice(price) {
    if (typeof price !== 'number') return price
    return String(Number(price).toFixed(2)).replace(/\B(?=(\d{3})+(?!\d))/g, ',')
  }

}

